home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / fastkey.exe / DEMO1.PAS < prev    next >
Pascal/Delphi Source File  |  1992-12-11  |  2KB  |  42 lines

  1. Program Demo1;
  2.  
  3. {***************************************************************************
  4. Purpose:  To demonstrate how Turbo Pascal (and nearly any other DOS app)
  5.           handles the keyboard.
  6. ***************************************************************************}
  7.  
  8. Uses
  9.   Crt;
  10.  
  11. Const
  12.   Esc   = #27;         { Scan codes used for keys by the program }
  13.   Left  = #75;
  14.   Right = #77;
  15.   Y = 20;
  16.  
  17. Var
  18.   Key                  { Used to track the keys that are pressed }
  19.          : Char;
  20.   X                    { Current location of the "ship" }
  21.          : Integer;
  22.  
  23. Begin
  24.   ClrScr;
  25.   writeln ('FastKey Demonstration - Before FastKey is installed.  Press Esc to exit.');
  26.   X := 40;                                  { set initial location of ship }
  27.   repeat
  28.     GotoXY(X,Y);  write('X');               { display the ship }
  29.     Key := ReadKey;                         { get any key pressed }
  30.     if Key = #0 then Begin                  { handle any ship movement }
  31.       Key := ReadKey;                       { get the extended function key }
  32.       if Key = Left then Begin              { move the ship left }
  33.         GotoXY(X,Y);  write(' ');           { erase the ship }
  34.         if X > 1 then Dec(X);               { update ship location }
  35.       End else if Key = Right then Begin    { move the ship right }
  36.         GotoXY(X,Y);  write(' ');           { erase the ship }
  37.         if X<80 then Inc(X);                { update location of ship }
  38.       End;
  39.     End;
  40.   until Key = Esc;
  41.   ClrScr;
  42. End. {Demo 1}